﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMS.Chess.CommonLayer
{
    public abstract class AStandardChessPiece : AChessPiece
    {
        public AStandardChessPiece(AChessBoard board, ChessColor color)
            : base(board, color)
        {

        }

        public override bool IsValidMoveTarget(ABoardPosition targetPosition)
        {
            StandardBoardPosition tp = targetPosition as StandardBoardPosition;

            if (tp == null)
                throw new InvalidOperationException("Invalid targetPosition");

            List<ABoardPosition> possibleMoves = this.GetPossibleMoves();
            foreach (ABoardPosition position in possibleMoves)
            {
                // will be null if invalid, if() still works
                StandardBoardPosition p = position as StandardBoardPosition;
                if (tp == p)
                {
                    return true;
                }
            }

            return false;
        }
    }
}
